package cn.duxiaod.demo.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 3.实现Callable复写call方法创建线程
 */
public class MyThreadTest3 implements Callable<String> {
    @Override
    public String call() throws Exception {
        return Thread.currentThread().getName();
    }

    public static void main(String[] args) {
        FutureTask futureTask = new FutureTask<String>(new MyThreadTest3());
        new Thread(futureTask).start();
        new Thread(futureTask).start();
        new Thread(futureTask).start();
        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
